﻿using Microsoft.VisualStudio.TestTools.UnitTesting;
using AMatysiak.Methods;
using System;

namespace AMatysiakTest.Methods
{
    [TestClass]
    public class SubstrTest
    {
        [TestMethod]
        public void emptyText()
        {
            string substr = "".Substr(0);
            Assert.AreEqual("", substr);
        }

        [TestMethod]
        [ExpectedException(typeof(ArgumentOutOfRangeException))]
        public void lengthIsMoreThenRealLength()
        {
            "".Substr(1);
        }

        [TestMethod]
        [ExpectedException(typeof(ArgumentOutOfRangeException))]
        public void minusLengthIsMoreThenRealLength()
        {
            "".Substr(-1);
        }

        [TestMethod]
        public void getSubstringFromBegining()
        {
            string substr = "Ale urwał!".Substr(3);
            Assert.AreEqual("Ale", substr);
        }

        [TestMethod]
        public void getSubstringAsNormal()
        {
            string substr = "Ale urwał!".Substr(0, 3);
            Assert.AreEqual("Ale", substr);
        }

        [TestMethod]
        public void getSubstringFromFewChars()
        {
            string substr = "Ale urwał!".Substr(4, 5);
            Assert.AreEqual("urwał", substr);
        }

        [TestMethod]
        public void getSubstringExceptLastChar()
        {
            string substr = "Ale urwał!".Substr(-1);
            Assert.AreEqual("Ale urwał", substr);
        }

        [TestMethod]
        public void getSubstringExceptLastCharFromFewChars()
        {
            string substr = "Ale urwał!".Substr(4, -1);
            Assert.AreEqual("urwał", substr);
        }
    }
}
